const BASEURL = "https://yuke.shuoyeah.com/";
const VERSION = '1.0.0'


const uToast = (param) => {
	uni.showToast({
		title: param.tit,
		icon: param.icon || 'none',
		duration: param.number || 2000
	});
}
const requests = (param, success) => {
	if (param.is_loading) {
		uni.showLoading({
			title: '加载中'
		});
	}
	uni.request({
		url: BASEURL + param.url,
		method: param.methods || 'POST',
		data: param.data,
		header: {
			'content-type': 'application/json',
			'token': uni.getStorageSync('token')
		},
		success(res) {
			uni.hideLoading();
			switch (res.data.code) {
				case 1:
					return success(res);
					break;
				case 10001:
					uni.reLaunch({
						url: "/pages/submit_form/login"
					})
					break;
				default:
					uni.showModal({
						title: '提示',
						showCancel: false,
						content: res.data.msg || '程序异常，稍后再试。',
						success: function(res) {
							if (res.confirm) {}
						}
					})
					break;
			}
		},
		fail(res) {
			uni.hideLoading();
			uni.showToast({
				title: res.data.msg || '获取数据失败，请稍后再试！',
				icon: 'none',
				duration:  2000
			});
		},
		complete() {
			if (param.closeLoad) {
				uni.hideLoading();
			}
		}
	})
}

module.exports = {
	requests,
	uToast,
	BASEURL,
	VERSION
}
